
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * This is the join connection handler.
 * 
 * @author jillsanluis
 */
public class ListeningThread extends Thread {

    private ServerSocket serverSocket = null;
    private boolean alive = true;

    public ListeningThread(int port) throws IOException {
        super("ListenerThreadHandler");
        serverSocket = new ServerSocket(port);
        System.out.println("Created new Thread to listen to peers");
    }

    @Override
    public void run() {

        while (alive) {

            Socket peerSocket = null;

            try {
                peerSocket = serverSocket.accept();

                // add the new peer to pool
                Mazewar.addToSocketPool(peerSocket);

            } catch (IOException ie) {
                // do nothing!
                ie.printStackTrace();
            }

        }
    }
}
